
import Vue from 'vue'
/**
 * 毫秒值 转换成 年月日
 * @param  {Date}   value) {               let time [description]
 * @return {[type]}        [description]
 */
Vue.filter('time-formater-no-hour', (value) => {
  if (!value) return ''
  // 返回处理后的值
  let time = new Date(value)
  let year = time.getFullYear()
  let month = (time.getMonth() < 9 ? '0' : '') + (time.getMonth() + 1)
  let day = (time.getDate() < 10 ? '0' : '') + time.getDate()
  return year + '-' + month + '-' + day
})

/**
 * 毫秒值 转换成 年月日 时分
 * @param  {Date}   value) {               let time [description]
 * @return {[type]}        [description]
 */
Vue.filter('time-formater-has-hour', (value) => {
  if (!value) return ''
  // 返回处理后的值
  let time = new Date(value)
  let year = time.getFullYear()
  let month = (time.getMonth() < 9 ? '0' : '') + (time.getMonth() + 1)
  let day = (time.getDate() < 10 ? '0' : '') + time.getDate()
  let hour = (time.getHours() < 10 ? '0' : '') + time.getHours()
  let minute = (time.getMinutes() < 10 ? '0' : '') + time.getMinutes()
  let second = (time.getSeconds() < 10 ? '0' : '') + time.getSeconds()
  return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
})
Vue.filter('time-formater-trans-hour', (value) => {
  // 返回处理后的值
  let time = new Date(value)
  let year = time.getFullYear()
  let month = (time.getMonth() < 9 ? '0' : '') + (time.getMonth() + 1)
  let day = (time.getDate() < 10 ? '0' : '') + time.getDate()
  let hour = (time.getHours() < 10 ? '0' : '') + time.getHours()
  let minute = (time.getMinutes() < 10 ? '0' : '') + time.getMinutes()
  let second = (time.getSeconds() < 10 ? '0' : '') + time.getSeconds()
  return  hour + ':' + minute + ':' + second + ' ' +  month + '-' + day +'-' +year
})
Vue.filter('time-formater-no-second', (value) => {
  // 返回处理后的值
  let time = new Date(value)
  let year = time.getFullYear()
  let month = (time.getMonth() < 9 ? '0' : '') + (time.getMonth() + 1)
  let day = (time.getDate() < 10 ? '0' : '') + time.getDate()
  let hour = (time.getHours() < 10 ? '0' : '') + time.getHours()
  let minute = (time.getMinutes() < 10 ? '0' : '') + time.getMinutes()
  return year + '-' + month + '-' + day + ' ' + hour + ':' + minute
})
/**
 * 毫秒值 转换成 时分
 */
Vue.filter('time-formater-only-hour', (value) => {
  let time = new Date(value)
  let hour = (time.getHours() < 10 ? '0' : '') + time.getHours()
  let minute = (time.getMinutes() < 10 ? '0' : '') + time.getMinutes()
  let second = (time.getSeconds() < 10 ? '0' : '') + time.getSeconds()
  return hour + ':' + minute + ':' + second
})
/**
 * 月-日-年
 */
Vue.filter('time-formater-only-year', (value) => {
  let time = new Date(value)
  let year = time.getFullYear()
  let month = (time.getMonth() < 9 ? '0' : '') + (time.getMonth() + 1)
  let day = (time.getDate() < 10 ? '0' : '') + time.getDate()
  return month + '-' + day + '-' + year
})
/**
 * 分 转换成 元
 * @param  {String}   value)
 * @return {[String]}        [description]
 */
Vue.filter('fenToYuan', (value) => {
  return (parseFloat(value) / 100).toFixed(2)
})
/**
 * 把单位中文转换成英文
 * @return {[type]} [description]
 */
// 日期单位
Vue.filter('dayUnitEn', (value) => {
  let map = {'2': 'Day', '0': 'Week', '1': 'Month'}
  return map[value]
})


Vue.filter('search-target', (value, searchText, textClass) => {
  function replaceReg (reg, str) {
    return str.replace(reg, (m) => {
      return '<span class="' + textClass + '">' + m + '</span>'
    })
  }
  let strRegex = '' + searchText
  let regex = new RegExp(strRegex, 'gi')
  value = replaceReg(regex, value)
  return value
})
/**
 * 把布尔值转‘是否’
 * @return {[type]} [description]
 */
Vue.filter('booleanFilter', (val) => {
  if (val === true) {
    return '是'
  } else if (val === false) {
    return '否'
  }
  return val
})
